<?php
class Product_Model_PutawayLog
{

	private $_table;
	public function __construct(){
		$this->_table = new Product_Model_DbTable_PutawayLog();
	}

	public function add($row){
		return $this->_table->insert($row);
	}

	public function getByValue($value,$field='pl_id'){
        $select = $this->_table->getAdapter()->select();
        $table  = $this->_table->info('name');
        $select->from($table,'*');
        $select->where("{$field} = ?",$value);
		return $this->_table->getAdapter()->fetchRow($select);
	}

	public  function getByCondition($condition=array(),$type='*',$page="",$pageSize=""){
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table,$type);
        $select->where("1 =?",1);
		if(isset($condition['putaway_code']) && !empty($condition['putaway_code'])){
			$select->where("putaway_code = ?",$condition['putaway_code']);
		}
		if(isset($condition['pl_type']) && !empty($condition['pl_type'])){
			$select->where("pl_type = ?",$condition['pl_type']);
		}
        if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }else{
            if($pageSize>0 and $page>0)
            {
                $start =($page-1)*$pageSize;
                $select->limit($pageSize,$start);
            }
			$sql=$select->__toString();
		    return $this->_table->getAdapter()->fetchAll($sql);
        }
	}

}